import service from '@/utils/request'

export const useProjectApi = (id: number) => {
	return service.get('/gen/project/' + id)
}

export const useProjectSubmitApi = (dataForm: any) => {
	if (dataForm.id) {
		return service.put('/gen/project', dataForm)
	} else {
		return service.post('/gen/project', dataForm)
	}
}

export const useDownloadApi = (id: Number) => {
	return service.get('/gen/project/download/' + id)
}

export const useDownloadZipApi = (id: Number) => {
	location.href = import.meta.env.VITE_API_URL + '/gen/project/download-zip/' + id
}

export const usePreviewApi = (projectId: Number) => {
	return service.get('/gen/project/preview?projectId=' + projectId)
}

//下载单个模板代码
export const useDownloadTemplateApi = (params: any) => {
	location.href =
		import.meta.env.VITE_API_URL +
		'/gen/project/download-template-content?projectId=' +
		params.projectId +
		'&templateId=' +
		params.templateId +
		'&tableId=' +
		params.tableId +
		'&templateGroupType=' +
		params.templateGroupType
}

//获取目录树形结构
export const useTreeDataApi = (projectId: Number) => {
	return service.get('/gen/project/tree-data?projectId=' + projectId)
}

export const useProjectListApi = () => {
	return service.get('/gen/project/list')
}

export const useDataSourceTableListApi = (id: Number, tableName: string) => {
	return service.get('/gen/project/table/list?projectId=' + id + '&tableName=' + tableName)
}
